package com.ruoyi.backend.service.Impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.backendEnum.EcologicalSupervisionReportException;
import com.ruoyi.backend.mapper.EcologicalSupervisionReportMapper;
import com.ruoyi.backend.pojo.EcologicalSupervisionReport;
import com.ruoyi.backend.service.EcologicalSupervisionReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class EcologicalSupervisionReportServiceImpl implements EcologicalSupervisionReportService {

    @Autowired
    private EcologicalSupervisionReportMapper ecologicalSupervisionReportMapper;

    @Override
    public void create(EcologicalSupervisionReport ecologicalSupervisionReport) {

        ecologicalSupervisionReportMapper.create(ecologicalSupervisionReport);
    }

    @Override
    public void delete(Integer superviseId) {
        if (ecologicalSupervisionReportMapper.getCountId(superviseId) == 0) {
            throw new ServiceException(EcologicalSupervisionReportException.ECOLOGICAL_SUPERVISION_REPORT_DATA_NOT_EXIST);
        }
        ecologicalSupervisionReportMapper.delete(superviseId);
    }

    @Override
    public void update(EcologicalSupervisionReport ecologicalSupervisionReport) {
        if (ecologicalSupervisionReportMapper.getCountId(ecologicalSupervisionReport.getSuperviseId()) == 0) {
            throw new ServiceException(EcologicalSupervisionReportException.ECOLOGICAL_SUPERVISION_REPORT_DATA_NOT_EXIST);
        }
        ecologicalSupervisionReportMapper.update(ecologicalSupervisionReport);
    }

    @Override
    public List<EcologicalSupervisionReport> search(String mineId, String superviseType, LocalDate superviseTimeStart, LocalDate superviseTimeEnd) {
        List<EcologicalSupervisionReport> ecologicalSupervisionReportList = ecologicalSupervisionReportMapper.search(mineId, superviseType, superviseTimeStart, superviseTimeEnd);
//        if (ecologicalSupervisionReportList.isEmpty()) {
//            throw new ServiceException(EcologicalSupervisionReportException.ECOLOGICAL_SUPERVISION_REPORT_DATA_NOT_FOUND);
//        }
        return ecologicalSupervisionReportMapper.search(mineId, superviseType, superviseTimeStart, superviseTimeEnd);
    }

    @Override
    public List<EcologicalSupervisionReport> serachAll() {
        return ecologicalSupervisionReportMapper.searchAll();
    }
}
